package com.hy.${packageCode}.server.web.api;


import com.hy.${packageCode}.common.api.AbstractApi;
import com.hy.${packageCode}.common.api.result.ApiPageResult;
import com.hy.${packageCode}.common.api.result.ApiResult;
import com.hy.${packageCode}.common.defs.CommonDefs;
import com.hy.${packageCode}.server.common.param.${classCode}Param;
import com.hy.${packageCode}.server.common.param.${classCode}QueryParam;
import com.hy.${packageCode}.server.common.param.${classCode}UpdateParam;
import com.hy.${packageCode}.server.common.vo.${classCode}ItemVO;
import com.hy.${packageCode}.server.common.vo.${classCode}VO;
import com.hy.${packageCode}.server.core.service.${classCode}Service;
import com.hy.${packageCode}.server.web.convert.${classCode}Convert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "${objName}接口")
@Slf4j
@RestController
@RequestMapping(CommonDefs.RESTFUL_URI_CONTEXT + "/${urlCode}")
public class ${classCode}Api extends AbstractApi {

    @Autowired
    private ${classCode}Convert ${objCode}Convert;
    @Autowired
    private ${classCode}Service ${objCode}Service;

    @Operation(summary = "分页列表")
    @PostMapping("/page/{pageNum}/{pageSize}")
    public ApiResult<ApiPageResult<${classCode}ItemVO>> page(@RequestBody @Validated ${classCode}QueryParam queryParam, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        return ApiResult.success(${objCode}Service.page(queryParam, pageNum, pageSize));
    }


    @Operation(summary = "查看")
    @GetMapping("/view/{id}")
    public ApiResult<${classCode}VO> view(@Parameter(description = "摄像仪区域ID") @PathVariable Long id) {
        return ApiResult.success(${objCode}Convert.convertVO(${objCode}Service.detail(id)));
    }

    @Operation(summary = "新增")
    @PostMapping("/add")
    public ApiResult<Boolean> add(@Validated @RequestBody ${classCode}Param param) {
        ${objCode}Service.add(param);
        return ApiResult.success();
    }

    @Operation(summary = "编辑")
    @PostMapping("/update")
    public ApiResult<Boolean> update(@Validated @RequestBody ${classCode}UpdateParam param) {
        ${objCode}Service.update(param);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @PostMapping("/delete/{id}")
    public ApiResult<Boolean> delete(@Parameter(description = "ID") @PathVariable Long id) {
        ${objCode}Service.delete(id);
        return ApiResult.success();
    }

}
